//
//  InvestTableViewCell.m
//  WBBaseProject
//
//  Created by 吴斌 on 2018/3/5.
//  Copyright © 2018年 吴斌. All rights reserved.
//

#import "InvestTableViewCell.h"
#import <UIImageView+WebCache.h>
@implementation InvestTableViewCell

//- (void )layoutSubviews {
//    
//    // always try to set frame in layoutSubviews
//    [super layoutSubviews];
//    CGRect frame = CGRectMake(0, 5, self.contentView.frame.size.width , self.contentView.frame.size.height - 10);
//    
//    UIView *backView = [[UIView alloc] initWithFrame:frame];
//    
//    self.selectedBackgroundView = backView;
//    
//    self.selectedBackgroundView.backgroundColor = [UIColor clearColor];
//    
//}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (IBAction)bidClick:(id)sender {
    
    if (self.bidClick) {
        self.bidClick();
    }
}

// 配置cell选中状态
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
//    if (selected) {
//        self.bgView.backgroundColor = [UIColor whiteColor];
//    } 
}

- (void)setData:(NSDictionary *)data
{
    self.nameLb.text = data[@"custName"];
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:data[@"custHeadImg"]] placeholderImage:nil];
    self.gradeLb.text = data[@"riskLevelName"];
    self.detailLb.text = data[@"crmName"];
    double money = [data[@"contractMoney"] doubleValue];
    self.moneyLb.text = [NSString stringWithFormat:@"%.2f元",money];
    self.progressView.progress = [data[@"progress"] floatValue] * 0.01;
    self.percentLb.attributedText = [self reateWith:[NSString stringWithFormat:@"%@",data[@"rate"]]];
    self.monthLb.text = [NSString stringWithFormat:@"%@月",data[@"periods"]];
    if ([data[@"guarantorStatus"] isEqual:@1]) {
        self.markIV.hidden = NO;
    }else{
        self.markIV.hidden = YES;
    }
//    
//    periods
}
- (void)setIsEdit:(BOOL)isEdit
{
    _isEdit = isEdit;
    
    if (isEdit) {
        self.chooseBtn.hidden = NO;
        [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(50);
        }];
    }else{
        self.chooseBtn.hidden = YES;
        [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(12);
        }];
    }
    
}
- (IBAction)chooseClick:(UIButton*)sender {
    
    sender.selected = !sender.selected;
    if (self.chooseBack) {
        self.chooseBack(sender.selected);
    }
}

- (NSAttributedString *)reateWith:(NSString *)reate
{
    NSMutableAttributedString * firstPart = [[NSMutableAttributedString alloc] initWithString:reate];
    NSDictionary * firstAttributes = @{ NSFontAttributeName:[UIFont boldSystemFontOfSize:24],NSForegroundColorAttributeName:WB_RGBColor(255, 78, 78)};
    [firstPart setAttributes:firstAttributes range:NSMakeRange(0,firstPart.length)];
    NSMutableAttributedString * secondPart = [[NSMutableAttributedString alloc] initWithString:@"%"];
    NSDictionary * secondAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:WB_RGBColor(255, 78, 78),};
    [secondPart setAttributes:secondAttributes range:NSMakeRange(0,secondPart.length)];
    [firstPart appendAttributedString:secondPart];
    return firstPart;
}

@end
